{extend name="wap/default/base" /}
{block name="resources"}
<link rel="stylesheet" type="text/css" href="__TEMP__/{$style}/public/css/foundation.css">
<link rel="stylesheet" type="text/css" href="__TEMP__/{$style}/public/css/common-v4.4.css">
<link rel="stylesheet" type="text/css" href="__TEMP__/{$style}/public/css/normalize.css">
<link rel="stylesheet" type="text/css" href="__TEMP__/{$style}/public/css/dis-v4.4.css">
<style>
.arrow {position: absolute; right:30px;top: 48%; }
.extract { margin: 44px 0px 0px 0px;background:#FFF;padding:20px 15px;}
input {width: 100%;height: 23px;}
.extract-monynumber .columns {padding: 10px;background:#fff;}
.tip-text{color:#FF4040;margin-top:45px;padding:10px;margin-bottom:0;}
.button.red {padding: 8px 0px;line-height: 1.33;border-radius: 3px;background: #FF4040;margin:auto;border-color: #ec522c;width:95%;}
.btn_all{width:100%;text-align:center;}
.horn-text{background:none;color:#000000;border:none;}
.extract-number .number {font-size: 16px; }
.side-nav li{ position: relative;}
</style>
{/block} 

{block name="main"}
<section class="head">
	<a class="head_back" href="javascript:window.history.go(-1);"><i class="icon-back"></i></a>
	<div class="head-title" >申请提现</div>
</section>

<!--submit errow tip begin-->
    <div data-alert class="alert-box alert" id="errerMsg" style="display: none;"><a href="#" class="close">&times;</a></div>
    <!--submit errow tip end-->
    <!--content begin-->
        <div class="panel extract">
		        <div class="commision-total"><span class="span-title" style="color:#000000;">可提现金额：</span><span class="number" style="font-size:18px;color:#FF4040;"id="Amount">¥{$account}</span></div>
        </div>
        
        <div class="panel extract-account" style="border:0px;">
            <ul class="side-nav" >
                 {if condition="count($account_list) eq 0"}
                	<li ><a href="{:__URL('APP_MAIN/member/accountlist?shop_id='.$shop_id)}" style="padding:6px 15px;"><span>请添加提现账号 <br></span><i class="arrow"></i></a></li>
                {else/}
                	<li>
                	 {volist name="account_list" id="vo"}
					          <a href="{:__URL('APP_MAIN/member/accountlist?shop_id='.$shop_id)}" style="padding:6px 15px;" >
					               <span>{$vo.branch_bank_name}<br>{$vo.account_number} </span>
					               <i class="arrow" ></i></a>
					          </a>
					          <input type="hidden" value="{$vo.id}" id="bank_account_id"/>
	                 {/volist} 
	                </li>
                {/if}
            </ul>
        </div>
        <div class="row extract-monynumber">
            <div class="large-12 columns">
                <input type="text" class="" style="border:0px;" id="money" placeholder="请输入提取金额">
            </div>
            {if condition="$cash neq '' && $poundage neq ''"}
            <div class="tip-text">最低提现金额为<span id="MinaAmountCash">{$cash}</span>元 ，必须为<span id="IntTimes">{$poundage}</span>的整数倍</div>
            {else/}
            <div class="tip-text">最低提现金额为<span id="MinaAmountCash">0</span>元 ，必须为<span id="IntTimes">1</span>的整数倍</div>
            {/if}
        </div>
        <div class="btn_all">
	        <a href="javascript:;" onclick="btnSave()" class="button red">立即申请</a>
            {if condition="$withdraw_message neq ''"}
	        <div class="horn-text"> 注:{$withdraw_message}</div> 
            {/if}
        </div>
    
     <input type="hidden" value="{$shop_id}" id="id"/>
{/block}
{block name="bottom"}{/block}
{block name="javascript"}
 <script type="text/javascript">
   function btnSave(){
	        var shop_id = $("#id").val();
        	var bank_account_id = $("#bank_account_id").val();
            var cash = $.trim($("#money").val());
            var MaxCashAmount = $.trim($("#Amount").text());
            var MinaAmountCash = $.trim($("#MinaAmountCash").text());
            var IntTimes = $.trim($("#IntTimes").html());

            MaxCashAmount = MaxCashAmount.substr(1);
            if(bank_account_id == null || bank_account_id == ""){
            	showBox("未添加提现账号");
	            return;
            }
            var reg = /^\+?[1-9][0-9]*$/;
      
            if (reg.test(cash)) {
            	cash = Number(cash);
                MaxCashAmount = Number(MaxCashAmount);
                MinaAmountCash = Number(MinaAmountCash);
                if (cash > 0) {
                    if (cash <= MaxCashAmount) {
                        if (cash >= MinaAmountCash) {
                            if (cash % parseInt(IntTimes) == 0) {
                            
                                $.ajax({
                                	type:"post",
                                    url: "{:__URL('APP_MAIN/member/towithdraw')}",
                                    data: { "bank_account_id": bank_account_id, "cash": cash},
                                    success: function (res) {
                                        if (res['code'] >0) {
                                        	showBox("已提交申请，等待审核...");
                                            window.location.href = __URL("APP_MAIN/member/balancewater?shop_id="+shop_id) ;
                                        } else {
                                        	showBox(res.outmessage);
                                        } 
                                    }
                                })
                            } else {
                                //$("#CashAmount").focus();
                                showBox("提现金额必须是" + IntTimes + "的整数倍");
                                return false;
                            }
                        } else {
                            //$("#CashAmount").focus();
                            showBox("提现金额必须大于" + MinaAmountCash);
                            return false;
                        }


                    } else {
                        //$("#CashAmount").focus();
                        showBox("可提现金额最大为" + MaxCashAmount);
                        return false;
                    }
                } else {
                    //$("#CashAmount").focus();
                    showBox("当前不可提现");
                    return false;
                }
            } else {
                //$("#CashAmount").focus();
                showBox("输入金额不合法");
                return false;
            }
        }
    </script>
{/block}